package com.ruoyi.gt.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.gt.domain.GtBookListInfo;
import com.ruoyi.gt.service.IGtBookListInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 图书卡片Controller
 *
 * @author xkang
 * @date 2020-06-19
 */
@RestController
@RequestMapping("/gtbook")
public class GtBookListInfoController extends BaseController
{
    @Autowired
    private IGtBookListInfoService gtBookListInfoService;

    /**
     * 查询图书卡片列表
     */
    @PreAuthorize("@ss.hasPermi('gt:gtbook:list')")
    @GetMapping("/list")
    public TableDataInfo list(GtBookListInfo gtBookListInfo)
    {
        startPage();
        List<GtBookListInfo> list = gtBookListInfoService.selectGtBookListInfoList(gtBookListInfo);
        return getDataTable(list);
    }

    /**
     * 导出图书卡片列表
     */
    @PreAuthorize("@ss.hasPermi('gt:gtbook:export')")
    @Log(title = "图书卡片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GtBookListInfo gtBookListInfo) throws IOException
    {
        List<GtBookListInfo> list = gtBookListInfoService.selectGtBookListInfoList(gtBookListInfo);
        ExcelUtil<GtBookListInfo> util = new ExcelUtil<GtBookListInfo>(GtBookListInfo.class);
        util.exportExcel(response, list, "gtbook");
    }

    /**
     * 获取图书卡片详细信息
     */
    @PreAuthorize("@ss.hasPermi('gt:gtbook:query')")
    @GetMapping(value = "/{bookId}")
    public AjaxResult getInfo(@PathVariable("bookId") Long bookId)
    {
        return AjaxResult.success(gtBookListInfoService.selectGtBookListInfoById(bookId));
    }

    /**
     * 新增图书卡片
     */
    @PreAuthorize("@ss.hasPermi('gt:gtbook:add')")
    @Log(title = "图书卡片", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody GtBookListInfo gtBookListInfo)
    {
        return toAjax(gtBookListInfoService.insertGtBookListInfo(gtBookListInfo));
    }

    /**
     * 修改图书卡片
     */
    @PreAuthorize("@ss.hasPermi('gt:gtbook:edit')")
    @Log(title = "图书卡片", businessType = BusinessType.UPDATE)
    @PutMapping("edit")
    public AjaxResult edit(@RequestBody GtBookListInfo gtBookListInfo)
    {
        return toAjax(gtBookListInfoService.updateGtBookListInfo(gtBookListInfo));
    }

    /**
     * 删除图书卡片
     */
    @PreAuthorize("@ss.hasPermi('gt:gtbook:remove')")
    @Log(title = "图书卡片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bookIds}")
    public AjaxResult remove(@PathVariable Long[] bookIds)
    {
        return toAjax(gtBookListInfoService.deleteGtBookListInfoByIds(bookIds));
    }
}
